package com.shelpe.services.sinbad.controller.sinbad;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.shelpe.services.sinbad.controller.dto.AutoDriveAdgroupRecord;
import com.shelpe.services.sinbad.controller.dto.CampaignEffectDto;
import com.shelpe.services.sinbad.controller.dto.Focus12daysRecord;
import com.shelpe.services.sinbad.controller.dto.FocusAdgroupRecord;
import com.shelpe.services.sinbad.controller.dto.FocusRecord;
import com.shelpe.services.sinbad.entity.enums.AutoOptimizationMark;
import com.shelpe.services.sinbad.entity.enums.FocusStage;
import com.shelpe.services.sinbad.entity.enums.TimeMark;
import com.shelpe.services.sinbad.entity.jpa.Adgroup;
import com.shelpe.services.sinbad.entity.jpa.AutoProductQueue;
import com.shelpe.services.sinbad.entity.jpa.Campaign;
import com.shelpe.services.sinbad.entity.jpa.CampaignLog;
import com.shelpe.services.sinbad.entity.jpa.DriveType;
import com.shelpe.services.sinbad.entity.jpa.KeywordsLog;
import com.shelpe.services.sinbad.entity.jpa.KeywordsLog.Action;
import com.shelpe.services.sinbad.entity.jpa.OnlineStatus;
import com.shelpe.services.sinbad.entity.jpa.vo.ConvertPlatformVo;
import com.shelpe.services.sinbad.entity.jpa.vo.PlatformVo;
import com.shelpe.services.sinbad.repository.jpa.AdgroupRepository;
import com.shelpe.services.sinbad.repository.jpa.AutoProductQueueRepository;
import com.shelpe.services.sinbad.repository.jpa.CampaignLogRepository;
import com.shelpe.services.sinbad.repository.jpa.CampaignRepository;
import com.shelpe.services.sinbad.repository.jpa.KeywordsLogRepository;
import com.shelpe.services.sinbad.service.PlatformService;
import com.shelpe.services.sinbad.service.rpt.CampaignService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(value = "/sinbadservice/v2")
@Api("v2版计划相关的API")
public class Campaign2Controller {
	@Autowired
	private CampaignRepository campaignRepository;
	@Autowired
	private PlatformService platformService;
	@Autowired
	private CampaignService campaignService;
	@Autowired
	private CampaignLogRepository campaignLogRepository;
	@Autowired
	private KeywordsLogRepository keywordsLogRepository;
	@Autowired
	private AdgroupRepository adgroupRepository;
	@Autowired
	private AutoProductQueueRepository autoProductQueueRepository;

	 @CrossOrigin(allowCredentials="true", allowedHeaders="*", methods={RequestMethod.GET,  
	            RequestMethod.POST, RequestMethod.DELETE, RequestMethod.OPTIONS,  
	            RequestMethod.HEAD, RequestMethod.PUT, RequestMethod.PATCH}, origins="*")
	@ApiOperation(value = "批量获取推广计划")
	@RequestMapping(method = RequestMethod.GET, path = "/users/{user_id}/campaigns")
	@ResponseBody
	public List<CampaignEffectDto> query(@PathVariable("user_id") final long userID,
			@RequestParam(name = "campaign_id", required = false, defaultValue = "0") final long campaignID,
			@RequestParam(name = "need_rpt", required = false, defaultValue = "false") boolean needRpt,
			@RequestParam(name = "start", required = false) String start,
			@RequestParam(name = "end", required = false) String end,
			@RequestParam(name = "device", required = false, defaultValue = "all") String device,
			@RequestParam(name = "type", required = false) String type) {
		List<Campaign> pos = this.campaignRepository.findAll(new Specification<Campaign>() {
			@Override
			public Predicate toPredicate(Root<Campaign> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				Predicate p = cb.equal(root.get("userID"), userID);
				if (campaignID > 0) {
					p = cb.and(p, cb.equal(root.get("autoID"), campaignID));
				}
				return p;
			}
		});
		List<CampaignEffectDto> dtos = new ArrayList<CampaignEffectDto>();
		Map<Long, CampaignEffectDto> dtoMap = new HashMap<Long, CampaignEffectDto>();
		if (pos != null && pos.size() > 0) {
			for (Campaign po : pos) {
				CampaignEffectDto dto = new CampaignEffectDto();
				dto.from(po);
				dto.setPlatform(new ConvertPlatformVo());
				PlatformVo vo = platformService.unserialize(po.getPlatform());
				if (vo != null) {
					dto.getPlatform().fromSearch(vo);
					dto.getPlatform().fromNonSearch(vo);
					dto.getPlatform().setMobileDiscount(vo.getMobileDiscount());
					dto.getPlatform().setOutsideDiscount(vo.getOutsideDiscount());
				}
				dto.setAdgroupNum(this.adgroupRepository.countByCampaignID(po.getAutoID()));
				dtoMap.put(po.getAutoID(), dto);
				dtos.add(dto);
			}
		}

		if (needRpt) {
			if (pos != null && pos.size() > 0) {
				for (Campaign po : pos) {
					CampaignEffectDto dto = dtoMap.get(po.getAutoID());
					if (dto != null) {
						dto.setEffect(this.campaignService.campaignMetric(po.getAutoID(), start, end, device));
					}

				}
			}
		}

		return dtos;
	}

	@ApiOperation(value = "低价引流宝贝的自动优化操作记录汇总")
	@RequestMapping(method = RequestMethod.GET, path = "/campaigns/{campaign_id}/adgroups/@autoRecord")
	public List<AutoDriveAdgroupRecord> query(@PathVariable("campaign_id") final long campaignID) {
		List<AutoDriveAdgroupRecord> records = new ArrayList<AutoDriveAdgroupRecord>();
		List<Adgroup> adgroups = adgroupRepository.findByCampaignID(campaignID);
		List<Long> adgroupIDs = new ArrayList<Long>();

		Date date = DateUtils.truncate(new Date(), Calendar.DATE);
		List<CampaignLog> timeDiscountLogs = campaignLogRepository.findByCampaignIDAndUpdatedTimeAfterAndAction(
				campaignID, date, com.shelpe.services.sinbad.entity.jpa.CampaignLog.Action.AUTO_UPDATE_SCHEDULE);
		if (timeDiscountLogs != null && timeDiscountLogs.size() > 0) {
			for (CampaignLog log : timeDiscountLogs) {
				AutoDriveAdgroupRecord record = new AutoDriveAdgroupRecord();
				record.setRecord(AutoOptimizationMark.timeDiscount.name());
				record.setRecordTime(log.getUpdatedTime());
				records.add(record);
			}
		}

		if (adgroups != null && adgroups.size() > 0) {

			if(adgroups.get(0).getChangeTime() == null) {
				addRecord("", AutoOptimizationMark.basic.name(), adgroups.get(0).getCreateTime(), records);
				addRecord("", AutoOptimizationMark.finishCreative.name(), adgroups.get(0).getCreateTime(), records);
			}else {
				addRecord("", AutoOptimizationMark.basic.name(), adgroups.get(0).getChangeTime(), records);
				addRecord("", AutoOptimizationMark.finishCreative.name(), adgroups.get(0).getChangeTime(), records);
			}
			//addRecord("", AutoOptimizationMark.basic.name(), adgroups.get(0).getCreateTime(), records);
			for (Adgroup adgroup : adgroups) {
				adgroupIDs.add(adgroup.getAutoID());
			}
			List<AutoProductQueue> queues = autoProductQueueRepository
					.findByAdgroupIDInAndInitialKeywordCountGreaterThan(adgroupIDs, 0);
			int sumKeywords = 0;
			if (queues != null && queues.size() > 0) {
				for (AutoProductQueue queue : queues) {
					sumKeywords += queue.getInitialKeywordCount();
				}
				addRecord(queues.size() + "," + adgroups.size() + "," + sumKeywords,
						AutoOptimizationMark.addingKeywords.name(), queues.get(0).getCreateTime(), records);
				if (queues.size() == adgroups.size()) {
					addRecord("", AutoOptimizationMark.finishAddKeywords.name(),
							adgroups.get(adgroups.size() - 1).getCreateTime(), records);
				}
			}
			List<KeywordsLog> matchLogs = keywordsLogRepository.findByAdgroupIDInAndActionAndUpdatedTimeAfter(
					adgroupIDs, KeywordsLog.Action.AUTO_CHANGE_MATCHSCOPE, date);
			List<KeywordsLog> changePriceLogs = keywordsLogRepository.findByAdgroupIDInAndActionAndUpdatedTimeAfter(
					adgroupIDs, KeywordsLog.Action.AUTO_CHANGE_PRICE, date);
			List<KeywordsLog> delLogs = keywordsLogRepository.findByAdgroupIDInAndActionAndUpdatedTimeAfter(adgroupIDs,
					KeywordsLog.Action.AUTO_DEL_KEYWORD, date);
			List<KeywordsLog> addLogs = keywordsLogRepository.findByAdgroupIDInAndActionAndUpdatedTimeAfter(adgroupIDs,
					KeywordsLog.Action.AUTO_NEW_KEYWORD, date);
			if (matchLogs != null && matchLogs.size() > 0) {
				addRecord(matchLogs.size() + "", AutoOptimizationMark.matchMode.name(),
						matchLogs.get(0).getUpdatedTime(), records);
			}
			if (changePriceLogs != null && changePriceLogs.size() > 0) {
				addRecord(changePriceLogs.size() + "", AutoOptimizationMark.adjustPrice.name(),
						changePriceLogs.get(0).getUpdatedTime(), records);
			}
			if (delLogs != null && delLogs.size() > 0) {
				addRecord(delLogs.size() + "", AutoOptimizationMark.deleteKeywords.name(),
						delLogs.get(0).getUpdatedTime(), records);
			}
			if (addLogs != null && addLogs.size() > 0) {
				addRecord(addLogs.size() + "", AutoOptimizationMark.addKeywords.name(), addLogs.get(0).getUpdatedTime(),
						records);
			}
			//因为下面会排序、所以将此放到上面  shiben
			//addRecord("", AutoOptimizationMark.finishCreative.name(), adgroups.get(0).getCreateTime(), records);
		}
		Collections.sort(records, new Comparator<AutoDriveAdgroupRecord>() {
			@Override
			public int compare(AutoDriveAdgroupRecord o1, AutoDriveAdgroupRecord o2) {
				return o2.getRecordTime().compareTo(o1.getRecordTime());
			}
		});
		return records;
	}

	@ApiOperation(value = "重力主打的自动优化操作记录汇总")
	@RequestMapping(method = RequestMethod.GET, path = "/campaigns/{campaign_id}/adgroups/@focusRecord")
	public List<FocusRecord> queryFocusRecord(@PathVariable("campaign_id") final long campaignID) {
		List<Adgroup> adgroups = adgroupRepository.findByCampaignIDAndDriveTypeAndOnlineStatusOrderByCreateTime(
				campaignID, DriveType.focus, OnlineStatus.online);
		List<Long> adgroupIDs = new ArrayList<Long>();
		Date date = DateUtils.truncate(new Date(), Calendar.DATE);

		List<FocusRecord> focusRecords = new ArrayList<FocusRecord>();
		if (adgroups != null && adgroups.size() > 0) {
			/**
			 * 创建阶段start
			 */
			FocusRecord createStage = new FocusRecord();
			List<FocusAdgroupRecord> createStageList = new ArrayList<FocusAdgroupRecord>();

			// 第一阶段
			FocusAdgroupRecord createStageFirst = new FocusAdgroupRecord();
			List<AutoDriveAdgroupRecord> createFirstDetailRecords = new ArrayList<AutoDriveAdgroupRecord>();
			addRecord(adgroups.size() + "", TimeMark.first.name(), adgroups.get(0).getCreateTime(),
					createFirstDetailRecords);
			createStageFirst.setTimeMark(TimeMark.first.name());
			createStageFirst.setRecords(createFirstDetailRecords);
			// 第二阶段
			FocusAdgroupRecord createStageSecond = new FocusAdgroupRecord();
			List<AutoDriveAdgroupRecord> createSecondDetailRecords = new ArrayList<AutoDriveAdgroupRecord>();
			addRecord("", TimeMark.second.name(), DateUtils.addMinutes(adgroups.get(0).getCreateTime(), 5),
					createSecondDetailRecords);
			createStageSecond.setTimeMark(TimeMark.second.name());
			createStageSecond.setRecords(createSecondDetailRecords);
			// 第三阶段
			FocusAdgroupRecord createStageThird = new FocusAdgroupRecord();
			List<AutoDriveAdgroupRecord> createThirdDetailRecords = new ArrayList<AutoDriveAdgroupRecord>();
			for (Adgroup adgroup : adgroups) {
				adgroupIDs.add(adgroup.getAutoID());
			}
			List<AutoProductQueue> queues = autoProductQueueRepository
					.findByAdgroupIDInAndInitialKeywordCountGreaterThan(adgroupIDs, 0);
			int sumKeywords = 0;
			if (queues != null && queues.size() > 0) {
				for (AutoProductQueue queue : queues) {
					sumKeywords += queue.getInitialKeywordCount();
				}
				addRecord(adgroups.size() + "," + sumKeywords, TimeMark.third.name(),
						queues.get(0).getLastModifiedTime(), createThirdDetailRecords);
				createStageThird.setTimeMark(TimeMark.third.name());
				createStageThird.setRecords(createThirdDetailRecords);
			}

			createStageList.add(createStageFirst);
			createStageList.add(createStageSecond);
			createStageList.add(createStageThird);

			createStage.setFocusStage(FocusStage.create.name());
			createStage.setRecords(createStageList);
			/**
			 * 创建阶段 end
			 */

			/**
			 * 诊断阶段 start
			 */
			FocusRecord diagnosisStage = new FocusRecord();
			List<FocusAdgroupRecord> diagnosisStageList = new ArrayList<FocusAdgroupRecord>();

			// 第一阶段
			FocusAdgroupRecord diagnosisStageFirst = new FocusAdgroupRecord();
			List<AutoDriveAdgroupRecord> diagnosisFirstDetailRecords = new ArrayList<AutoDriveAdgroupRecord>();
			Date diagnosisStageFirstTime = DateUtils.addHours(adgroups.get(0).getCreateTime(), 1);
			addRecord("", TimeMark.first.name(), diagnosisStageFirstTime, diagnosisFirstDetailRecords);
			diagnosisStageFirst.setTimeMark(TimeMark.first.name());
			diagnosisStageFirst.setRecords(diagnosisFirstDetailRecords);

			// 第二阶段
			FocusAdgroupRecord diagnosisStageSecond = new FocusAdgroupRecord();
			List<AutoDriveAdgroupRecord> diagnosisSecondDetailRecords = new ArrayList<AutoDriveAdgroupRecord>();
			Date diagnosisStageSecondTime = DateUtils.addMinutes(diagnosisStageFirstTime, 5);
			addRecord(adgroups.size() + "", TimeMark.second.name(), diagnosisStageSecondTime,
					diagnosisSecondDetailRecords);
			diagnosisStageSecond.setTimeMark(TimeMark.first.name());
			diagnosisStageSecond.setRecords(diagnosisSecondDetailRecords);

			// 第三阶段
			FocusAdgroupRecord diagnosisStageThird = new FocusAdgroupRecord();
			List<AutoDriveAdgroupRecord> diagnosisThirdDetailRecords = new ArrayList<AutoDriveAdgroupRecord>();
			Date diagnosisStageThirdTime = DateUtils.addMinutes(diagnosisStageSecondTime, 5);
			addRecord("", TimeMark.third.name(), diagnosisStageThirdTime, diagnosisThirdDetailRecords);
			diagnosisStageThird.setTimeMark(TimeMark.third.name());
			diagnosisStageThird.setRecords(diagnosisThirdDetailRecords);

			// 第四阶段
			FocusAdgroupRecord diagnosisStageFourth = new FocusAdgroupRecord();
			List<AutoDriveAdgroupRecord> diagnosisFourthDetailRecords = new ArrayList<AutoDriveAdgroupRecord>();
			Date diagnosisStageFourthTime = DateUtils.addMinutes(diagnosisStageThirdTime, 30);
			addRecord("", TimeMark.fourth.name(), diagnosisStageFourthTime, diagnosisFourthDetailRecords);
			diagnosisStageFourth.setTimeMark(TimeMark.fourth.name());
			diagnosisStageFourth.setRecords(diagnosisFourthDetailRecords);

			// 第五阶段
			FocusAdgroupRecord diagnosisStageFifth = new FocusAdgroupRecord();
			List<AutoDriveAdgroupRecord> diagnosisFifthDetailRecords = new ArrayList<AutoDriveAdgroupRecord>();
			Date diagnosisStageFifthTime = DateUtils.addMinutes(diagnosisStageFourthTime, 10);
			addRecord("", TimeMark.fifth.name(), diagnosisStageFifthTime, diagnosisFifthDetailRecords);
			diagnosisStageFifth.setTimeMark(TimeMark.fifth.name());
			diagnosisStageFifth.setRecords(diagnosisFifthDetailRecords);

			diagnosisStageList.add(diagnosisStageFirst);
			diagnosisStageList.add(diagnosisStageSecond);
			diagnosisStageList.add(diagnosisStageThird);
			diagnosisStageList.add(diagnosisStageFourth);
			diagnosisStageList.add(diagnosisStageFifth);

			diagnosisStage.setFocusStage(FocusStage.diagnosis.name());
			diagnosisStage.setRecords(diagnosisStageList);

			/**
			 * 诊断阶段 end
			 */

			long days = ((new Date()).getTime() - adgroups.get(0).getCreateTime().getTime()) / (1000 * 60 * 60 * 24);
			Date createTime = adgroups.get(0).getCreateTime();
			List<KeywordsLog> logs = new ArrayList<KeywordsLog>();
			if (days >= 1) {
				List<KeywordsLog> matchLogs = keywordsLogRepository.findByAdgroupIDInAndActionAndUpdatedTimeBefore(
						adgroupIDs, KeywordsLog.Action.AUTO_CHANGE_MATCHSCOPE, date);
				List<KeywordsLog> changePriceLogs = keywordsLogRepository
						.findByAdgroupIDInAndActionAndUpdatedTimeBefore(adgroupIDs,
								KeywordsLog.Action.AUTO_CHANGE_PRICE, date);
				List<KeywordsLog> delLogs = keywordsLogRepository.findByAdgroupIDInAndActionAndUpdatedTimeBefore(
						adgroupIDs, KeywordsLog.Action.AUTO_DEL_KEYWORD, date);
				List<KeywordsLog> addLogs = keywordsLogRepository.findByAdgroupIDInAndActionAndUpdatedTimeBefore(
						adgroupIDs, KeywordsLog.Action.AUTO_NEW_KEYWORD, date);
				logs.addAll(addLogs);
				logs.addAll(changePriceLogs);
				logs.addAll(matchLogs);
				logs.addAll(delLogs);
			}
			this.filterLogs(logs, createTime, days, focusRecords);

			focusRecords.add(createStage);
			focusRecords.add(diagnosisStage);
		}
		return focusRecords;
	}

	private void filterLogs(List<KeywordsLog> logs, Date time, long days, List<FocusRecord> focusRecords) {
		long createTime = time.getTime();
		time = DateUtils.truncate(time, Calendar.DATE);
		Date today = DateUtils.truncate(new Date(), Calendar.DATE);
		List<KeywordsLog> addLog1 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> addLog2 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> addLog3 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> addLog4 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> addLog5 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> addLog6 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> addLog7 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> addLog8 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> addLog9 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> addLog10 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> addLog11 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> addLog12 = new ArrayList<KeywordsLog>();

		List<KeywordsLog> deleteLog1 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> deleteLog2 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> deleteLog3 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> deleteLog4 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> deleteLog5 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> deleteLog6 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> deleteLog7 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> deleteLog8 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> deleteLog9 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> deleteLog10 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> deleteLog11 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> deleteLog12 = new ArrayList<KeywordsLog>();

		List<KeywordsLog> matchLog1 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> matchLog2 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> matchLog3 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> matchLog4 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> matchLog5 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> matchLog6 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> matchLog7 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> matchLog8 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> matchLog9 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> matchLog10 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> matchLog11 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> matchLog12 = new ArrayList<KeywordsLog>();

		List<KeywordsLog> priceLog1 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> priceLog2 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> priceLog3 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> priceLog4 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> priceLog5 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> priceLog6 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> priceLog7 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> priceLog8 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> priceLog9 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> priceLog10 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> priceLog11 = new ArrayList<KeywordsLog>();
		List<KeywordsLog> priceLog12 = new ArrayList<KeywordsLog>();

		// 添加关键词
		for (KeywordsLog log : logs) {
			long createDays = (log.getUpdatedTime().getTime() - createTime) / (1000 * 60 * 60 * 24);
			Date updateDate = DateUtils.truncate(log.getUpdatedTime(), Calendar.DATE);			
			if (createDays == 1) {
				if (log.getAction().getValue() == Action.AUTO_NEW_KEYWORD.getValue()) {
					addLog1.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_PRICE.getValue()) {
					priceLog1.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_DEL_KEYWORD.getValue()) {
					deleteLog1.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_MATCHSCOPE.getValue()) {
					matchLog1.add(log);
				}
			} else if (createDays == 2) {
				if (log.getAction().getValue() == Action.AUTO_NEW_KEYWORD.getValue()) {
					addLog2.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_PRICE.getValue()) {
					priceLog2.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_DEL_KEYWORD.getValue()) {
					deleteLog2.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_MATCHSCOPE.getValue()) {
					matchLog2.add(log);
				}
			} else if (createDays == 3) {
				if (log.getAction().getValue() == Action.AUTO_NEW_KEYWORD.getValue()) {
					addLog3.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_PRICE.getValue()) {
					priceLog3.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_DEL_KEYWORD.getValue()) {
					deleteLog3.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_MATCHSCOPE.getValue()) {
					matchLog3.add(log);
				}
			} else if (createDays == 4) {
				if (log.getAction().getValue() == Action.AUTO_NEW_KEYWORD.getValue()) {
					addLog4.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_PRICE.getValue()) {
					priceLog4.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_DEL_KEYWORD.getValue()) {
					deleteLog4.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_MATCHSCOPE.getValue()) {
					matchLog4.add(log);
				}
			} else if (createDays == 5) {
				if (log.getAction().getValue() == Action.AUTO_NEW_KEYWORD.getValue()) {
					addLog5.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_PRICE.getValue()) {
					priceLog5.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_DEL_KEYWORD.getValue()) {
					deleteLog5.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_MATCHSCOPE.getValue()) {
					matchLog5.add(log);
				}
			} 

			if (updateDate.equals(DateUtils.addDays(today, -6))) {
				if (log.getAction().getValue() == Action.AUTO_NEW_KEYWORD.getValue()) {
					addLog6.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_PRICE.getValue()) {
					priceLog6.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_DEL_KEYWORD.getValue()) {
					deleteLog6.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_MATCHSCOPE.getValue()) {
					matchLog6.add(log);
				}
			} else if (updateDate.equals(DateUtils.addDays(today, -5))) {
				if (log.getAction().getValue() == Action.AUTO_NEW_KEYWORD.getValue()) {
					addLog7.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_PRICE.getValue()) {
					priceLog7.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_DEL_KEYWORD.getValue()) {
					deleteLog7.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_MATCHSCOPE.getValue()) {
					matchLog7.add(log);
				}
			} else if (updateDate.equals(DateUtils.addDays(today, -4))) {
				if (log.getAction().getValue() == Action.AUTO_NEW_KEYWORD.getValue()) {
					addLog8.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_PRICE.getValue()) {
					priceLog8.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_DEL_KEYWORD.getValue()) {
					deleteLog8.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_MATCHSCOPE.getValue()) {
					matchLog8.add(log);
				}
			} else if (updateDate.equals(DateUtils.addDays(today, -3))) {
				if (log.getAction().getValue() == Action.AUTO_NEW_KEYWORD.getValue()) {
					addLog9.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_PRICE.getValue()) {
					priceLog9.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_DEL_KEYWORD.getValue()) {
					deleteLog9.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_MATCHSCOPE.getValue()) {
					matchLog9.add(log);
				}
			} else if (updateDate.equals(DateUtils.addDays(today, -2))) {
				if (log.getAction().getValue() == Action.AUTO_NEW_KEYWORD.getValue()) {
					addLog10.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_PRICE.getValue()) {
					priceLog10.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_DEL_KEYWORD.getValue()) {
					deleteLog10.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_MATCHSCOPE.getValue()) {
					matchLog10.add(log);
				}
			} else if (updateDate.equals(DateUtils.addDays(today, -1))) {
				if (log.getAction().getValue() == Action.AUTO_NEW_KEYWORD.getValue()) {
					addLog11.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_PRICE.getValue()) {
					priceLog11.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_DEL_KEYWORD.getValue()) {
					deleteLog11.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_MATCHSCOPE.getValue()) {
					matchLog11.add(log);
				}
			} else if (updateDate.equals(today)) {
				if (log.getAction().getValue() == Action.AUTO_NEW_KEYWORD.getValue()) {
					addLog12.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_PRICE.getValue()) {
					priceLog12.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_DEL_KEYWORD.getValue()) {
					deleteLog12.add(log);
				} else if (log.getAction().getValue() == Action.AUTO_CHANGE_MATCHSCOPE.getValue()) {
					matchLog12.add(log);
				}
			}
		}

		List<AutoDriveAdgroupRecord> day1records = new ArrayList<AutoDriveAdgroupRecord>();
		List<AutoDriveAdgroupRecord> day2records = new ArrayList<AutoDriveAdgroupRecord>();
		List<AutoDriveAdgroupRecord> day3records = new ArrayList<AutoDriveAdgroupRecord>();
		List<AutoDriveAdgroupRecord> day4records = new ArrayList<AutoDriveAdgroupRecord>();
		List<AutoDriveAdgroupRecord> day5records = new ArrayList<AutoDriveAdgroupRecord>();
		List<AutoDriveAdgroupRecord> day6records = new ArrayList<AutoDriveAdgroupRecord>();
		List<AutoDriveAdgroupRecord> day7records = new ArrayList<AutoDriveAdgroupRecord>();
		List<AutoDriveAdgroupRecord> day8records = new ArrayList<AutoDriveAdgroupRecord>();
		List<AutoDriveAdgroupRecord> day9records = new ArrayList<AutoDriveAdgroupRecord>();
		List<AutoDriveAdgroupRecord> day10records = new ArrayList<AutoDriveAdgroupRecord>();
		List<AutoDriveAdgroupRecord> day11records = new ArrayList<AutoDriveAdgroupRecord>();
		List<AutoDriveAdgroupRecord> day12records = new ArrayList<AutoDriveAdgroupRecord>();

		if (days >= 1) {
			addRecord("", AutoOptimizationMark.first.name(), DateUtils.addMinutes(DateUtils.addDays(time, 1), 10),
					day1records);
			if (days >= 2) {
				addRecord("", AutoOptimizationMark.first.name(), DateUtils.addMinutes(DateUtils.addDays(time, 2), 5),
						day2records);
				if (days >= 3) {
					addRecord("", AutoOptimizationMark.first.name(),
							DateUtils.addMinutes(DateUtils.addDays(time, 3), 5), day3records);
					addRecord("", AutoOptimizationMark.second.name(),
							DateUtils.addMinutes(DateUtils.addDays(time, 3), 10), day3records);
					addRecord("", AutoOptimizationMark.third.name(),
							DateUtils.addMinutes(DateUtils.addDays(time, 3), 20), day3records);
					if (days >= 4) {
						addRecord("", AutoOptimizationMark.first.name(),
								DateUtils.addMinutes(DateUtils.addDays(time, 4), 5), day4records);
						if (days >= 5) {
							addRecord("", AutoOptimizationMark.first.name(),
									DateUtils.addMinutes(DateUtils.addDays(time, 5), 5), day5records);
							addRecord("", AutoOptimizationMark.second.name(),
									DateUtils.addMinutes(DateUtils.addDays(time, 5), 5), day5records);
							addRecord("", AutoOptimizationMark.last.name(),
									DateUtils.addMinutes(DateUtils.addDays(time, 6), -5), day5records);
							if (days >= 6) {
								addRecord("", AutoOptimizationMark.first.name(),
										DateUtils.addMinutes(DateUtils.addDays(today, -6), 5), day6records);
								addRecord("", AutoOptimizationMark.second.name(),
										DateUtils.addMinutes(DateUtils.addDays(today, -6), 10), day6records);
								addRecord("", AutoOptimizationMark.third.name(),
										DateUtils.addHours(DateUtils.addDays(today, -6), 6), day6records);
								if (days >= 7) {
									addRecord("", AutoOptimizationMark.first.name(),
											DateUtils.addMinutes(DateUtils.addDays(today, -5), 5), day7records);
									addRecord("", AutoOptimizationMark.second.name(),
											DateUtils.addMinutes(DateUtils.addDays(today, -5), 10), day7records);
									addRecord("", AutoOptimizationMark.third.name(),
											DateUtils.addHours(DateUtils.addDays(today, -5), 6), day7records);
									if (days >= 8) {
										addRecord("", AutoOptimizationMark.first.name(),
												DateUtils.addMinutes(DateUtils.addDays(today, -4), 5), day8records);
										addRecord("", AutoOptimizationMark.second.name(),
												DateUtils.addMinutes(DateUtils.addDays(today, -4), 10), day8records);
										addRecord("", AutoOptimizationMark.third.name(),
												DateUtils.addHours(DateUtils.addDays(today, -4), 6), day8records);
										if (days >= 9) {
											addRecord("", AutoOptimizationMark.first.name(),
													DateUtils.addMinutes(DateUtils.addDays(today, -3), 5), day9records);
											addRecord("", AutoOptimizationMark.second.name(),
													DateUtils.addMinutes(DateUtils.addDays(today, -3), 10), day9records);
											addRecord("", AutoOptimizationMark.third.name(),
													DateUtils.addHours(DateUtils.addDays(today, -3), 6), day9records);
											if (days >= 10) {
												addRecord("", AutoOptimizationMark.first.name(),
														DateUtils.addMinutes(DateUtils.addDays(today, -2), 5),
														day10records);
												addRecord("", AutoOptimizationMark.second.name(),
														DateUtils.addMinutes(DateUtils.addDays(today, -2), 10),
														day10records);
												addRecord("", AutoOptimizationMark.third.name(),
														DateUtils.addHours(DateUtils.addDays(today, -2), 6),
														day10records);
												if (days >= 11) {
													addRecord("", AutoOptimizationMark.first.name(),
															DateUtils.addMinutes(DateUtils.addDays(today, -1), 5),
															day11records);
													addRecord("", AutoOptimizationMark.second.name(),
															DateUtils.addMinutes(DateUtils.addDays(today, -1), 10),
															day11records);
													addRecord("", AutoOptimizationMark.third.name(),
															DateUtils.addHours(DateUtils.addDays(today, -1), 6),
															day11records);
													if (days >= 12) {
														addRecord("", AutoOptimizationMark.first.name(),
																DateUtils.addMinutes(today, 5),
																day12records);
														addRecord("", AutoOptimizationMark.second.name(),
																DateUtils.addMinutes(today, 10),
																day12records);
														addRecord("", AutoOptimizationMark.third.name(),
																DateUtils.addHours(today, 6),
																day12records);
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		if (addLog1.size() > 0) {
			addRecord(addLog1.size() + "", AutoOptimizationMark.addKeywords.name(), addLog1.get(0).getUpdatedTime(),
					day1records);
		}
		if (addLog2.size() > 0) {
			addRecord(addLog2.size() + "", AutoOptimizationMark.addKeywords.name(), addLog2.get(0).getUpdatedTime(),
					day2records);
		}
		if (addLog3.size() > 0) {
			addRecord(addLog3.size() + "", AutoOptimizationMark.addKeywords.name(), addLog3.get(0).getUpdatedTime(),
					day3records);
		}
		if (addLog4.size() > 0) {
			addRecord(addLog4.size() + "", AutoOptimizationMark.addKeywords.name(), addLog4.get(0).getUpdatedTime(),
					day4records);
		}
		if (addLog5.size() > 0) {
			addRecord(addLog5.size() + "", AutoOptimizationMark.addKeywords.name(), addLog5.get(0).getUpdatedTime(),
					day5records);
		}
		if (addLog6.size() > 0) {
			addRecord(addLog6.size() + "", AutoOptimizationMark.addKeywords.name(), addLog6.get(0).getUpdatedTime(),
					day6records);
		}
		if (addLog7.size() > 0) {
			addRecord(addLog7.size() + "", AutoOptimizationMark.addKeywords.name(), addLog7.get(0).getUpdatedTime(),
					day7records);
		}
		if (addLog8.size() > 0) {
			addRecord(addLog8.size() + "", AutoOptimizationMark.addKeywords.name(), addLog8.get(0).getUpdatedTime(),
					day8records);
		}
		if (addLog9.size() > 0) {
			addRecord(addLog9.size() + "", AutoOptimizationMark.addKeywords.name(), addLog9.get(0).getUpdatedTime(),
					day9records);
		}
		if (addLog10.size() > 0) {
			addRecord(addLog10.size() + "", AutoOptimizationMark.addKeywords.name(), addLog10.get(0).getUpdatedTime(),
					day10records);
		}
		if (addLog11.size() > 0) {
			addRecord(addLog11.size() + "", AutoOptimizationMark.addKeywords.name(), addLog11.get(0).getUpdatedTime(),
					day11records);
		}
		if (addLog12.size() > 0) {
			addRecord(addLog12.size() + "", AutoOptimizationMark.addKeywords.name(), addLog12.get(0).getUpdatedTime(),
					day12records);
		}

		if (priceLog1.size() > 0) {
			addRecord(priceLog1.size() + "", AutoOptimizationMark.adjustPrice.name(), priceLog1.get(0).getUpdatedTime(),
					day1records);
		}
		if (priceLog2.size() > 0) {
			addRecord(priceLog2.size() + "", AutoOptimizationMark.adjustPrice.name(), priceLog2.get(0).getUpdatedTime(),
					day2records);
		}
		if (priceLog3.size() > 0) {
			addRecord(priceLog3.size() + "", AutoOptimizationMark.adjustPrice.name(), priceLog3.get(0).getUpdatedTime(),
					day3records);
		}
		if (priceLog4.size() > 0) {
			addRecord(priceLog4.size() + "", AutoOptimizationMark.adjustPrice.name(), priceLog4.get(0).getUpdatedTime(),
					day4records);
		}
		if (priceLog5.size() > 0) {
			addRecord(priceLog5.size() + "", AutoOptimizationMark.adjustPrice.name(), priceLog5.get(0).getUpdatedTime(),
					day5records);
		}
		if (priceLog6.size() > 0) {
			addRecord(priceLog6.size() + "", AutoOptimizationMark.adjustPrice.name(), priceLog6.get(0).getUpdatedTime(),
					day6records);
		}
		if (priceLog7.size() > 0) {
			addRecord(priceLog7.size() + "", AutoOptimizationMark.adjustPrice.name(), priceLog7.get(0).getUpdatedTime(),
					day7records);
		}
		if (priceLog8.size() > 0) {
			addRecord(priceLog8.size() + "", AutoOptimizationMark.adjustPrice.name(), priceLog8.get(0).getUpdatedTime(),
					day8records);
		}
		if (priceLog9.size() > 0) {
			addRecord(priceLog9.size() + "", AutoOptimizationMark.adjustPrice.name(), priceLog9.get(0).getUpdatedTime(),
					day9records);
		}
		if (priceLog10.size() > 0) {
			addRecord(priceLog10.size() + "", AutoOptimizationMark.adjustPrice.name(),
					priceLog10.get(0).getUpdatedTime(), day10records);
		}
		if (priceLog11.size() > 0) {
			addRecord(priceLog11.size() + "", AutoOptimizationMark.adjustPrice.name(),
					priceLog11.get(0).getUpdatedTime(), day11records);
		}
		if (priceLog12.size() > 0) {
			addRecord(priceLog12.size() + "", AutoOptimizationMark.adjustPrice.name(),
					priceLog12.get(0).getUpdatedTime(), day12records);
		}

		if (matchLog1.size() > 0) {
			addRecord(matchLog1.size() + "", AutoOptimizationMark.matchMode.name(), matchLog1.get(0).getUpdatedTime(),
					day1records);
		}
		if (matchLog2.size() > 0) {
			addRecord(matchLog2.size() + "", AutoOptimizationMark.matchMode.name(), matchLog2.get(0).getUpdatedTime(),
					day2records);
		}
		if (matchLog3.size() > 0) {
			addRecord(matchLog3.size() + "", AutoOptimizationMark.matchMode.name(), matchLog3.get(0).getUpdatedTime(),
					day3records);
		}
		if (matchLog4.size() > 0) {
			addRecord(matchLog4.size() + "", AutoOptimizationMark.matchMode.name(), matchLog4.get(0).getUpdatedTime(),
					day4records);
		}
		if (matchLog5.size() > 0) {
			addRecord(matchLog5.size() + "", AutoOptimizationMark.matchMode.name(), matchLog5.get(0).getUpdatedTime(),
					day5records);
		}
		if (matchLog6.size() > 0) {
			addRecord(matchLog6.size() + "", AutoOptimizationMark.matchMode.name(), matchLog6.get(0).getUpdatedTime(),
					day6records);
		}
		if (matchLog7.size() > 0) {
			addRecord(matchLog7.size() + "", AutoOptimizationMark.matchMode.name(), matchLog7.get(0).getUpdatedTime(),
					day7records);
		}
		if (matchLog8.size() > 0) {
			addRecord(matchLog8.size() + "", AutoOptimizationMark.matchMode.name(), matchLog8.get(0).getUpdatedTime(),
					day8records);
		}
		if (matchLog9.size() > 0) {
			addRecord(matchLog9.size() + "", AutoOptimizationMark.matchMode.name(), matchLog9.get(0).getUpdatedTime(),
					day9records);
		}
		if (matchLog10.size() > 0) {
			addRecord(matchLog10.size() + "", AutoOptimizationMark.matchMode.name(), matchLog10.get(0).getUpdatedTime(),
					day10records);
		}
		if (matchLog11.size() > 0) {
			addRecord(matchLog11.size() + "", AutoOptimizationMark.matchMode.name(), matchLog11.get(0).getUpdatedTime(),
					day11records);
		}
		if (matchLog12.size() > 0) {
			addRecord(matchLog12.size() + "", AutoOptimizationMark.matchMode.name(), matchLog12.get(0).getUpdatedTime(),
					day12records);
		}

		if (deleteLog1.size() > 0) {
			addRecord(deleteLog1.size() + "", AutoOptimizationMark.deleteKeywords.name(),
					deleteLog1.get(0).getUpdatedTime(), day1records);
		}
		if (deleteLog2.size() > 0) {
			addRecord(deleteLog2.size() + "", AutoOptimizationMark.deleteKeywords.name(),
					deleteLog2.get(0).getUpdatedTime(), day2records);
		}
		if (deleteLog3.size() > 0) {
			addRecord(deleteLog3.size() + "", AutoOptimizationMark.deleteKeywords.name(),
					deleteLog3.get(0).getUpdatedTime(), day3records);
		}
		if (deleteLog4.size() > 0) {
			addRecord(deleteLog4.size() + "", AutoOptimizationMark.deleteKeywords.name(),
					deleteLog4.get(0).getUpdatedTime(), day4records);
		}
		if (deleteLog5.size() > 0) {
			addRecord(deleteLog5.size() + "", AutoOptimizationMark.deleteKeywords.name(),
					deleteLog5.get(0).getUpdatedTime(), day5records);
		}
		if (deleteLog6.size() > 0) {
			addRecord(deleteLog6.size() + "", AutoOptimizationMark.deleteKeywords.name(),
					deleteLog6.get(0).getUpdatedTime(), day6records);
		}
		if (deleteLog7.size() > 0) {
			addRecord(deleteLog7.size() + "", AutoOptimizationMark.deleteKeywords.name(),
					deleteLog7.get(0).getUpdatedTime(), day7records);
		}
		if (deleteLog8.size() > 0) {
			addRecord(deleteLog8.size() + "", AutoOptimizationMark.deleteKeywords.name(),
					deleteLog8.get(0).getUpdatedTime(), day8records);
		}
		if (deleteLog9.size() > 0) {
			addRecord(deleteLog9.size() + "", AutoOptimizationMark.deleteKeywords.name(),
					deleteLog9.get(0).getUpdatedTime(), day9records);
		}
		if (deleteLog10.size() > 0) {
			addRecord(deleteLog10.size() + "", AutoOptimizationMark.deleteKeywords.name(),
					deleteLog10.get(0).getUpdatedTime(), day10records);
		}
		if (deleteLog11.size() > 0) {
			addRecord(deleteLog11.size() + "", AutoOptimizationMark.deleteKeywords.name(),
					deleteLog11.get(0).getUpdatedTime(), day11records);
		}
		if (deleteLog12.size() > 0) {
			addRecord(deleteLog12.size() + "", AutoOptimizationMark.deleteKeywords.name(),
					deleteLog12.get(0).getUpdatedTime(), day12records);
		}

		Focus12daysRecord focus12daysRecord = new Focus12daysRecord();
		focus12daysRecord.setDay1records(day1records);
		focus12daysRecord.setDay2records(day2records);
		focus12daysRecord.setDay3records(day3records);
		focus12daysRecord.setDay4records(day4records);
		focus12daysRecord.setDay5records(day5records);
		focus12daysRecord.setDay6records(day6records);
		focus12daysRecord.setDay7records(day7records);
		focus12daysRecord.setDay8records(day8records);
		focus12daysRecord.setDay9records(day9records);
		focus12daysRecord.setDay10records(day10records);
		focus12daysRecord.setDay11records(day11records);
		focus12daysRecord.setDay12records(day12records);
		/**
		 * 培养期 start
		 */

		List<FocusAdgroupRecord> developAdgroupRecords = new ArrayList<FocusAdgroupRecord>();

		FocusAdgroupRecord developAdgroupRecord1 = new FocusAdgroupRecord();
		developAdgroupRecord1.setTimeMark(TimeMark.first.name());
		developAdgroupRecord1.setRecords(day1records);

		FocusAdgroupRecord developAdgroupRecord2 = new FocusAdgroupRecord();
		developAdgroupRecord2.setTimeMark(TimeMark.second.name());
		developAdgroupRecord2.setRecords(day2records);

		FocusAdgroupRecord developAdgroupRecord3 = new FocusAdgroupRecord();
		developAdgroupRecord3.setTimeMark(TimeMark.third.name());
		developAdgroupRecord3.setRecords(day3records);

		FocusAdgroupRecord developAdgroupRecord4 = new FocusAdgroupRecord();
		developAdgroupRecord4.setTimeMark(TimeMark.fourth.name());
		developAdgroupRecord4.setRecords(day4records);

		FocusAdgroupRecord developAdgroupRecord5 = new FocusAdgroupRecord();
		developAdgroupRecord5.setTimeMark(TimeMark.fifth.name());
		developAdgroupRecord5.setRecords(day5records);

		if (developAdgroupRecord1.getRecords() != null && developAdgroupRecord1.getRecords().size() > 0) {
			developAdgroupRecords.add(developAdgroupRecord1);
		}
		if (developAdgroupRecord2.getRecords() != null && developAdgroupRecord2.getRecords().size() > 0) {
			developAdgroupRecords.add(developAdgroupRecord2);
		}
		if (developAdgroupRecord3.getRecords() != null && developAdgroupRecord3.getRecords().size() > 0) {
			developAdgroupRecords.add(developAdgroupRecord3);
		}
		if (developAdgroupRecord4.getRecords() != null && developAdgroupRecord4.getRecords().size() > 0) {
			developAdgroupRecords.add(developAdgroupRecord4);
		}
		if (developAdgroupRecord5.getRecords() != null && developAdgroupRecord5.getRecords().size() > 0) {
			developAdgroupRecords.add(developAdgroupRecord5);
		}

		FocusRecord developRecord = new FocusRecord();
		developRecord.setFocusStage(FocusStage.develop.name());
		developRecord.setRecords(developAdgroupRecords);

		focusRecords.add(developRecord);

		/**
		 * 培养期 end
		 */

		/**
		 * 正常期 start
		 */

		List<FocusAdgroupRecord> dailyAdgroupRecords = new ArrayList<FocusAdgroupRecord>();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		FocusAdgroupRecord dailyAdgroupRecord6 = new FocusAdgroupRecord();
		if (day6records.size() > 0) {
			dailyAdgroupRecord6.setTimeMark(format.format(day6records.get(0).getRecordTime()).toString());
			dailyAdgroupRecord6.setRecords(day6records);
		}
		FocusAdgroupRecord dailyAdgroupRecord7 = new FocusAdgroupRecord();
		if (day7records.size() > 0) {
			dailyAdgroupRecord7.setTimeMark(format.format(day7records.get(0).getRecordTime()).toString());
			dailyAdgroupRecord7.setRecords(day7records);
		}
		FocusAdgroupRecord dailyAdgroupRecord8 = new FocusAdgroupRecord();
		if (day8records.size() > 0) {
			dailyAdgroupRecord8.setTimeMark(format.format(day8records.get(0).getRecordTime()).toString());
			dailyAdgroupRecord8.setRecords(day8records);
		}
		FocusAdgroupRecord dailyAdgroupRecord9 = new FocusAdgroupRecord();
		if (day9records.size() > 0) {
			dailyAdgroupRecord9.setTimeMark(format.format(day9records.get(0).getRecordTime()).toString());
			dailyAdgroupRecord9.setRecords(day9records);
		}
		FocusAdgroupRecord dailyAdgroupRecord10 = new FocusAdgroupRecord();
		if (day10records.size() > 0) {
			dailyAdgroupRecord10.setTimeMark(format.format(day10records.get(0).getRecordTime()).toString());
			dailyAdgroupRecord10.setRecords(day10records);
		}
		FocusAdgroupRecord dailyAdgroupRecord11 = new FocusAdgroupRecord();
		if (day11records.size() > 0) {
			dailyAdgroupRecord11.setTimeMark(format.format(day11records.get(0).getRecordTime()).toString());
			dailyAdgroupRecord11.setRecords(day11records);
		}
		FocusAdgroupRecord dailyAdgroupRecord12 = new FocusAdgroupRecord();
		if (day12records.size() > 0) {
			dailyAdgroupRecord12.setTimeMark(format.format(day12records.get(0).getRecordTime()).toString());
			dailyAdgroupRecord12.setRecords(day12records);
		}

		if (dailyAdgroupRecord12.getTimeMark() != null && !dailyAdgroupRecord12.getTimeMark().equals("")) {
			dailyAdgroupRecords.add(dailyAdgroupRecord12);
		}
		if (dailyAdgroupRecord11.getTimeMark() != null && !dailyAdgroupRecord11.getTimeMark().equals("")) {
			dailyAdgroupRecords.add(dailyAdgroupRecord11);
		}
		if (dailyAdgroupRecord10.getTimeMark() != null && !dailyAdgroupRecord10.getTimeMark().equals("")) {
			dailyAdgroupRecords.add(dailyAdgroupRecord10);
		}
		if (dailyAdgroupRecord9.getTimeMark() != null && !dailyAdgroupRecord9.getTimeMark().equals("")) {
			dailyAdgroupRecords.add(dailyAdgroupRecord9);
		}
		if (dailyAdgroupRecord8.getTimeMark() != null && !dailyAdgroupRecord8.getTimeMark().equals("")) {
			dailyAdgroupRecords.add(dailyAdgroupRecord8);
		}
		if (dailyAdgroupRecord7.getTimeMark() != null && !dailyAdgroupRecord7.getTimeMark().equals("")) {
			dailyAdgroupRecords.add(dailyAdgroupRecord7);
		}
		if (dailyAdgroupRecord6.getTimeMark() != null && !dailyAdgroupRecord6.getTimeMark().equals("")) {
			dailyAdgroupRecords.add(dailyAdgroupRecord6);
		}

		FocusRecord record = new FocusRecord();
		record.setFocusStage(FocusStage.daily.name());
		record.setRecords(dailyAdgroupRecords);

		focusRecords.add(record);

		/**
		 * 正常期 end
		 */
	}

	private void addRecord(String num, String record, Date recordTime, List<AutoDriveAdgroupRecord> records) {
		AutoDriveAdgroupRecord adgroupRecord = new AutoDriveAdgroupRecord();
		adgroupRecord.setNum(num);
		adgroupRecord.setRecord(record);
		adgroupRecord.setRecordTime(recordTime);
		records.add(adgroupRecord);
	}
}
